<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
                        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">

    <changeSet id="1" author="evst">

        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="person" />
            </not>
        </preConditions>

        <createTable tableName="person">
            <column name="id" type="int" autoIncrement="true">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="firstname" type="varchar(50)" />
            <column name="lastname" type="varchar(50)">
                <constraints nullable="false" />
            </column>
        </createTable>
    </changeSet>

    <changeSet id="2" author="evst">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="person" columnName="username" />
            </not>
        </preConditions>

        <addColumn tableName="person">
            <column name="username" type="varchar(8)" />
        </addColumn>
    </changeSet>

    <changeSet id="3" author="evst">
        <preConditions onFail="MARK_RAN">
            <sqlCheck expectedResult="0"> select count(*) from person </sqlCheck>
        </preConditions>

        <insert tableName="person">
            <column name="firstname">Evstafiy</column>
            <column name="lastname">Petrov</column>
            <column name="username">evst</column>
        </insert>
    </changeSet>

</databaseChangeLog>